/*******************************************************************************
"SCARCITY WITHOUT LEVIATHAN: The Violent Effects of Cocaine Supply Shortages
in the Mexican Drug War"
J.C. Castillo, D. Mejia, P. Restrepo
*********************************************************************************

This do file produces:
TABLE 4: "The differential effect of cocaine seizures in Colombia on violence in 
Mexico by distance from the nearest US entry point"

The table presents estimates of the interaction between cocaine seizures in Colombia
(measured at the monthly level in logs) on violence in Mexican municiplaities located
at different proximities to US entry points (measured in 100 km).

Dependent variables are:
- homicide rate
- drug-related homicides rate
- assassination of cartel members
- confrontation deaths
- assassination of government officials

Before running: set the path to current folder at line 31
*******************************************************************************/

clear all
set matsize 5000
set more off


*Set local folder
local folder /*SET THE PATH TO CURRENT FOLDER HERE*/

*Set working directory
cd `folder'
use dta/CastilloMejiaRestrepo.dta

keep if timeTS >= ym(2006,12)
tab year if  timeTS >= ym(2006,12), gen(yy)
local tscontrols t t2 t3 yy3 yy4 yy5

/*Main variable of interest: income gradient*/
gen supplyShock=log(cocaincCol)
gen interMain=-supplyShock*distEntradasPrinc*10
gen interPop=supplyShock*log(poblacion)


/*Time series differential controls*/
foreach var in `tscontrols'{
gen interdif_`var'=`var'*distEntradasPrinc
gen pandif_`var'=`var'*PANsupport
}

******************************************************************
* Table 4, panel 1 - Dep Var: INEGI HOMICIDE RATE 
******************************************************************

/*Create dependent variable: log INEGI Homicide rate*/
gen tasa_hom = homSIMBAD/poblacion * 100000 * 12
quietly sum tasa_hom if tasa_hom > 0 & codmpio != 9000, d
local shift=r(p90)
gen term=(tasa_hom+`shift')/tasa_hom
sum term
local adj=r(mean)
gen log_tasa_hom =`adj'*log(tasa_hom+`shift')

/*POISSON MODEL, All of Mexico - col 1/2*/
xi: xtpoisson tasa_hom interMain interdif_* i.timeTS , fe vce(robust)
estimates store e1

xi: xtpoisson tasa_hom interMain interdif_* i.timeTS pandif_*, fe vce(robust)
estimates store e2

/*LOG(P+X) MODEL, All of Mexico - col 3/4*/
xtreg log_tasa_hom interMain interdif_* i.timeTS, fe r cluster(codmpio)
estimates store e3

xtreg log_tasa_hom interMain interdif_* i.timeTS pandif_*, fe r cluster(codmpio)
estimates store e4

/*POISSON MODEL, Quintiles 1,2 - col 5/6*/
xi: xtpoisson tasa_hom interMain interdif_* i.timeTS if q12==1, fe vce(robust)
estimates store e5

xi: xtpoisson tasa_hom interMain interdif_* i.timeTS pandif_* if q12==1, fe vce(robust)
estimates store e6

/*LOG(P+X) MODEL, Quintiles 1,2 - col 7/8*/
xtreg log_tasa_hom interMain interdif_* i.timeTS if q12==1, fe r cluster(codmpio)
estimates store e7

xtreg log_tasa_hom interMain interdif_* i.timeTS pandif_* if q12==1, fe r cluster(codmpio)
estimates store e8

/*Export panel*/
estout e1 e2 e3 e4 e5 e6 e7 e8  using Tables/Table4pan1.tex, style(tex) ///
varlabels(interMain "Seizures in Colombia $\times$ Proximity to the U.S.") ///
cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N N_g, fmt(%7.0fc  %7.0fc) ///
labels("Observations" "Municipalities"))  collabels(none) eqlabels(none) keep(interMain) ///
order(interMain)  starlevels(\$^{*}\$ .1 \$^{**}\$ .05 \$^{***}\$ .01) nolabel replace mlabels(none)

drop tasa_hom term log_tasa_hom

******************************************************************
* Table 4, panel  2 - Dep Var: DRUG-RELATED HOMICIDES RATE
******************************************************************

/*Create dependent variables: log Drug-related homicide rate*/
gen tasa_hom = tothomicideB/poblacion * 100000 * 12
quietly sum tasa_hom if tasa_hom > 0 & codmpio != 9000, d
local shift=r(p90)
gen term=(tasa_hom+`shift')/tasa_hom
sum term
local adj=r(mean)
gen log_tasa_hom =`adj'*log(tasa_hom+`shift')


/*POISSON MODEL, All of Mexico - col 1/2*/
xi: xtpoisson tasa_hom interMain interdif_* i.timeTS , fe vce(robust)
estimates store e1

xi: xtpoisson tasa_hom interMain interdif_* i.timeTS pandif_*, fe vce(robust)
estimates store e2

/*LOG(P+X) MODEL, All of Mexico - col 3/4*/
xtreg log_tasa_hom interMain interdif_* i.timeTS, fe r cluster(codmpio)
estimates store e3

xtreg log_tasa_hom interMain interdif_* i.timeTS pandif_*, fe r cluster(codmpio)
estimates store e4

/*POISSON MODEL, Quintiles 1,2 - col 5/6*/
xi: xtpoisson tasa_hom interMain interdif_* i.timeTS if q12==1, fe vce(robust)
estimates store e5

xi: xtpoisson tasa_hom interMain interdif_* i.timeTS pandif_* if q12==1, fe vce(robust)
estimates store e6

/*LOG(P+X) MODEL, Quintiles 1,2 - col 7/8*/
xtreg log_tasa_hom interMain interdif_* i.timeTS if q12==1, fe r cluster(codmpio)
estimates store e7

xtreg log_tasa_hom interMain interdif_* i.timeTS pandif_* if q12==1, fe r cluster(codmpio)
estimates store e8

/*Export panel*/
estout e1 e2 e3 e4 e5 e6 e7 e8  using Tables/Table4pan2.tex, style(tex) ///
varlabels(interMain "Seizures in Colombia $\times$ Proximity to the U.S.") ///
cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N N_g, fmt(%7.0fc  %7.0fc) ///
labels("Observations" "R-squared"))  collabels(none) eqlabels(none)  keep(interMain) ///
order(interMain)  starlevels(\$^{*}\$ .1 \$^{**}\$ .05 \$^{***}\$ .01) nolabel replace mlabels(none)

drop tasa_hom term log_tasa_hom


******************************************************************
* Table 4, panel  3 - Dep Var: ASSASSINATION OF CARTEL MEMBERS
******************************************************************

/*Create dependent variables: log Assassination of cartel members*/
gen tasa_hom = ejehomicideB/poblacion * 100000 * 12
quietly sum tasa_hom if tasa_hom > 0 & codmpio != 9000, d
local shift=r(p90)
gen term=(tasa_hom+`shift')/tasa_hom
sum term
local adj=r(mean)
gen log_tasa_hom =`adj'*log(tasa_hom+`shift')


/*POISSON MODEL, All of Mexico - col 1/2*/
xi: xtpoisson tasa_hom interMain interdif_* i.timeTS , fe vce(robust)
estimates store e1

xi: xtpoisson tasa_hom interMain interdif_* i.timeTS pandif_*, fe vce(robust)
estimates store e2

/*LOG(P+X) MODEL, All of Mexico - col 3/4*/
xtreg log_tasa_hom interMain interdif_* i.timeTS, fe r cluster(codmpio)
estimates store e3

xtreg log_tasa_hom interMain interdif_* i.timeTS pandif_*, fe r cluster(codmpio)
estimates store e4

/*POISSON MODEL, Quintiles 1,2 - col 5/6*/
xi: xtpoisson tasa_hom interMain interdif_* i.timeTS if q12==1, fe vce(robust)
estimates store e5

xi: xtpoisson tasa_hom interMain interdif_* i.timeTS pandif_* if q12==1, fe vce(robust)
estimates store e6

/*LOG(P+X) MODEL, Quintiles 1,2 - col 7/8*/
xtreg log_tasa_hom interMain interdif_* i.timeTS if q12==1, fe r cluster(codmpio)
estimates store e7

xtreg log_tasa_hom interMain interdif_* i.timeTS pandif_* if q12==1, fe r cluster(codmpio)
estimates store e8

/*Export panel*/
estout e1 e2 e3 e4 e5 e6 e7 e8  using Tables/Table4pan3.tex, style(tex) ///
varlabels(interMain "Seizures in Colombia $\times$ Proximity to the U.S.") ///
cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N N_g, fmt(%7.0fc  %7.0fc) ///
labels("Observations" "R-squared"))  collabels(none) eqlabels(none) keep(interMain) ///
order(interMain)  starlevels(\$^{*}\$ .1 \$^{**}\$ .05 \$^{***}\$ .01) nolabel replace mlabels(none)

drop tasa_hom term log_tasa_hom


******************************************************************
* Table 4, panel  4 - Dep Var: CONFRONTATIONS DEATHS
******************************************************************

/*Create dependent variables: log Confrontation deaths*/
gen tasa_hom = enfhomicideB/poblacion * 100000 * 12
quietly sum tasa_hom if tasa_hom > 0 & codmpio != 9000, d
local shift=r(p90)
gen term=(tasa_hom+`shift')/tasa_hom
sum term
local adj=r(mean)
gen log_tasa_hom =`adj'*log(tasa_hom+`shift')

/*POISSON MODEL, All of Mexico - col 1/2*/
xi: xtpoisson tasa_hom interMain interdif_* i.timeTS , fe vce(robust)
estimates store e1

xi: xtpoisson tasa_hom interMain interdif_* i.timeTS pandif_*, fe vce(robust)
estimates store e2

/*LOG(P+X) MODEL, All of Mexico - col 3/4*/
xtreg log_tasa_hom interMain interdif_* i.timeTS, fe r cluster(codmpio)
estimates store e3

xtreg log_tasa_hom interMain interdif_* i.timeTS pandif_*, fe r cluster(codmpio)
estimates store e4

/*POISSON MODEL, Quintiles 1,2 - col 5/6*/
xi: xtpoisson tasa_hom interMain interdif_* i.timeTS if q12==1, fe vce(robust)
estimates store e5

xi: xtpoisson tasa_hom interMain interdif_* i.timeTS pandif_* if q12==1, fe vce(robust)
estimates store e6

/*LOG(P+X) MODEL, Quintiles 1,2 - col 7/8*/
xtreg log_tasa_hom interMain interdif_* i.timeTS if q12==1, fe r cluster(codmpio)
estimates store e7

xtreg log_tasa_hom interMain interdif_* i.timeTS pandif_* if q12==1, fe r cluster(codmpio)
estimates store e8

/*Export panel*/
estout e1 e2 e3 e4 e5 e6 e7 e8  using Tables/Table4pan4.tex, style(tex) ///
varlabels(interMain "Seizures in Colombia $\times$ Proximity to the U.S.") ///
cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N N_g, fmt(%7.0fc  %7.0fc) ///
labels("Observations" "R-squared"))  collabels(none) eqlabels(none) keep(interMain) ///
order(interMain)  starlevels(\$^{*}\$ .1 \$^{**}\$ .05 \$^{***}\$ .01) nolabel replace mlabels(none)

drop tasa_hom term log_tasa_hom

*********************************************************************
* Table 4, panel  5 - Dep Var: ASSASSINATION OF GOVERNMENT OFFICIALS
*********************************************************************

/*Create dependent variables: log Assassination of Government Officials*/
gen tasa_hom = agrehomicideB/poblacion * 100000 * 12
quietly sum tasa_hom if tasa_hom > 0 & codmpio != 9000, d
local shift=r(p90)
gen term=(tasa_hom+`shift')/tasa_hom
sum term
local adj=r(mean)
gen log_tasa_hom =`adj'*log(tasa_hom+`shift')

/*POISSON MODEL, All of Mexico - col 1/2*/
xi: xtpoisson tasa_hom interMain interdif_* i.timeTS , fe vce(robust)
estimates store e1

xi: xtpoisson tasa_hom interMain interdif_* i.timeTS pandif_*, fe vce(robust)
estimates store e2

/*LOG(P+X) MODEL, All of Mexico - col 3/4*/
xtreg log_tasa_hom interMain interdif_* i.timeTS, fe r cluster(codmpio)
estimates store e3

xtreg log_tasa_hom interMain interdif_* i.timeTS pandif_*, fe r cluster(codmpio)
estimates store e4

/*POISSON MODEL, Quintiles 1,2 - col 5/6*/
xi: xtpoisson tasa_hom interMain interdif_* i.timeTS if q12==1, fe vce(robust)
estimates store e5

xi: xtpoisson tasa_hom interMain interdif_* i.timeTS pandif_* if q12==1, fe vce(robust)
estimates store e6

/*LOG(P+X) MODEL, Quintiles 1,2 - col 7/8*/
xtreg log_tasa_hom interMain interdif_* i.timeTS if q12==1, fe r cluster(codmpio)
estimates store e7

xtreg log_tasa_hom interMain interdif_* i.timeTS pandif_* if q12==1, fe r cluster(codmpio)
estimates store e8

/*Export panel*/
estout e1 e2 e3 e4 e5 e6 e7 e8  using Tables/Table4pan5.tex, style(tex) ///
varlabels(interMain "Seizures in Colombia $\times$ Proximity to the U.S.") ///
cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N N_g, fmt(%7.0fc  %7.0fc) ///
labels("Observations" "R-squared"))  collabels(none) eqlabels(none) keep(interMain) ///
order(interMain)  starlevels(\$^{*}\$ .1 \$^{**}\$ .05 \$^{***}\$ .01) nolabel replace mlabels(none)

drop tasa_hom term log_tasa_hom
